先附上嘗試的指令與其紀錄,晚點再補上文字說明與心得。
透過建立新的 Solution、加入專案、到建置、測試,暸解如何透過 dotnet 命令列去執行。
# ~
$ mkdir dotnet-sln
$ cd dotnet-sln
# ~/dotnet-sln
$ dotnet new sln
$ ls
dotnet-sln.sln
# ~/dotnet-sln
$ mkdir WebProj
$ cd WebProj
# ~/dotnet-sln/WebProj
$ dotnet new mvc
The template "ASP.NET Core Web App (Model-View-Controller)" was created successfully.
This template contains technologies from parties other than Microsoft, see https://aka.ms/aspnetcore-template-3pn-210 for details.
Processing post-creation actions...
Running 'dotnet restore' on /Users/fntsr/Projects/dotnet-sln/WebProj/WebProj.csproj...
Restore completed in 522.21 ms for /Users/fntsr/dotnet-sln/WebProj/WebProj.csproj.
Restore succeeded.
$ ls
Controllers Properties appsettings.Development.json obj
Models Startup.cs appsettings.json wwwroot
Program.cs Views mvc-proj.csproj
$ cd ..
# ~/dotnet-sln
$ dotnet sln add WebProj/WebProj.csproj
Project `WebProj/WebProj.csproj` added to the solution.
# ~/dotnet-sln
$ dotnet build
Microsoft (R) Build Engine version 16.2.32702+c4012a063 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
Restore completed in 51.63 ms for /Users/fntsr/dotnet-sln/WebProj/WebProj.csproj.
WebProj -> /Users/fntsr/dotnet-sln/WebProj/bin/Debug/netcoreapp2.2/WebProj.dll
WebProj -> /Users/fntsr/dotnet-sln/WebProj/bin/Debug/netcoreapp2.2/WebProj.Views.dll
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:04.68
# ~/dotnet-sln
$ mkdir WebProj.Tests
$ cd WebProj.Tests
# ~/dotnet-sln/WebProj.Tests
$ dotnet new xunit
The template "xUnit Test Project" was created successfully.
Processing post-creation actions...
Running 'dotnet restore' on /Users/fntsr/dotnet-sln/WebProj.Tests/WebProj.Tests.csproj...
Restore completed in 21.5 sec for /Users/fntsr/dotnet-sln/WebProj.Tests/WebProj.Tests.csproj.
Restore succeeded.
$ ls
UnitTest1.cs WebProj.Tests.csproj obj
$ dotnet add reference ../WebProj/WebProj.csproj
# Reference `..\WebProj\WebProj.csproj` added to the project.
$ cd ..
# ~/dotnet-sln/
$ dotnet sln add WebProj.Tests/WebProj.Tests.csproj
Project `WebProj.Tests/WebProj.Tests.csproj` added to the solution.
$ dotnet build
Microsoft (R) Build Engine version 16.2.32702+c4012a063 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
Restore completed in 38.94 ms for /Users/fntsr/Projects/dotnet-sln/WebProj/WebProj.csproj.
Restore completed in 395.7 ms for /Users/fntsr/Projects/dotnet-sln/WebProj.Tests/WebProj.Tests.csproj.
WebProj -> /Users/fntsr/dotnet-sln/WebProj/bin/Debug/netcoreapp2.2/WebProj.dll
WebProj -> /Users/fntsr/dotnet-sln/WebProj/bin/Debug/netcoreapp2.2/WebProj.Views.dll
WebProj.Tests -> /Users/fntsr/dotnet-sln/WebProj.Tests/bin/Debug/netcoreapp2.2/WebProj.Tests.dll
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:02.61
# ~/dotnet-sln/
$ dotnet test
Test run for /Users/fntsr/Projects/dotnet-sln/WebProj.Tests/bin/Debug/netcoreapp2.2/WebProj.Tests.dll(.NETCoreApp,Version=v2.2)
Microsoft (R) Test Execution Command Line Tool Version 16.2.0-preview-20190606-02
Copyright (c) Microsoft Corporation. All rights reserved.
Starting test execution, please wait...
Test Run Successful.
Total tests: 1
Passed: 1
Total time: 1.6001 Seconds